import mountElement from "./mountElement";
import updateComponent from "./updateComponent";

export default function diffComponent(virtualDOM, oldComponent, oldDOM, container) {
    if(isSameComponent(virtualDOM, oldComponent)) {
        // 同一个组件
        updateComponent(virtualDOM, oldComponent, oldDOM, container)
    } else {
        // 不是同一个组件
        mountElement(virtualDOM, container, oldDOM)
    }
}

function isSameComponent(virtualDOM, oldComponent) {
    // 判断两个组件是否相同：组件的构造函数是否相同
    return oldComponent && virtualDOM.type === oldComponent.constructor;
}